public class Test3 {
    //leetcode 673 最长递增子序列的个数
    public int findNumberOfLIS(int[] nums) {
        //两个表，f表表示以i位置为结尾的所有子序列中最长递增子序列的长度
        //g表表示以i位置为结尾的所有子序列中最长子序列的长度
        int n = nums.length;
        int[] f = new int[n];
        int[] g = new int[n];
        for (int i = 0; i < n; i++) f[i] = g[i] = 1;
        int maxLen = 1,maxCount = 1;
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (nums[j] < nums[i]) {
                    if (f[j] + 1 == f[i]) g[i] += g[j];
                    else if (f[j] + 1 > f[i]) {
                        f[i] = f[j] + 1;
                        g[i] = g[j];
                    }
                }
            }
            if (maxLen == f[i]) maxCount += g[i];
            else if (f[i] > maxLen) {
                maxLen = f[i];
                maxCount = g[i];
            }
        }
        return maxCount;
    }
}
